#import "CustomNSString.h"

@implementation NSString (CustomNSString) 


/*
 _from の部分を _to に変換する
 */
- (NSString *)convertTo : (NSString *)_to
				   from : (NSString *)_from
{
	// NSMutableStringとか生成する前にチェック！
	NSRange checkRange = [ self rangeOfString : _from ];
	if (checkRange.location == NSNotFound) {
		return self;
	}
	
	BOOL loop = TRUE;
	NSMutableString *message = [ NSMutableString stringWithString : self ];
	
	do {
		NSRange range = [ message rangeOfString : _from ];
		
		if (range.location != NSNotFound) {
			[ message replaceCharactersInRange : range
									withString : _to ];
		} else {
			loop = FALSE;
		}
	} while (loop);
	
	return message;
}


/*
 全角数字を半角数字にする
 */
- (NSString *)convertNumber
{
	NSString *message = [ NSString stringWithString : self ];
	message = [ message convertTo : @"1" from : @"１" ];
	message = [ message convertTo : @"2" from : @"２" ];
	message = [ message convertTo : @"3" from : @"３" ];
	message = [ message convertTo : @"4" from : @"４" ];
	message = [ message convertTo : @"5" from : @"５" ];
	message = [ message convertTo : @"6" from : @"６" ];
	message = [ message convertTo : @"7" from : @"７" ];
	message = [ message convertTo : @"8" from : @"８" ];
	message = [ message convertTo : @"9" from : @"９" ];
	message = [ message convertTo : @"0" from : @"０" ];
	return message;
}	


/*
 ゔ系の変換
 */
- (NSString *)convertToV
{
	NSString *message = [ NSString stringWithString : self ];

	message = [ message convertTo : @"ば" from : @"ゔぁ" ];
	message = [ message convertTo : @"び" from : @"ゔぃ" ];
	message = [ message convertTo : @"べ" from : @"ゔぇ" ];
	message = [ message convertTo : @"ぼ" from : @"ゔぉ" ];
	message = [ message convertTo : @"ぶ" from : @"ゔ" ];
	
	message = [ message convertTo : @"バ" from : @"ヴァ" ];
	message = [ message convertTo : @"ビ" from : @"ヴィ" ];
	message = [ message convertTo : @"ベ" from : @"ヴェ" ];
	message = [ message convertTo : @"ボ" from : @"ヴォ" ];
	message = [ message convertTo : @"ブ" from : @"ヴ" ];
	
	return message;
}


/*
 半角カタカナを全角カタカナに
 */
- (NSString *)convertToZenkakuKana
{
	NSString *message = [ NSString stringWithString : self ];
	
	// 濁点・半濁点
	message = [ message convertTo : @"ガ" from : @"ｶﾞ" ];
	message = [ message convertTo : @"ギ" from : @"ｷﾞ" ];
	message = [ message convertTo : @"グ" from : @"ｸﾞ" ];
	message = [ message convertTo : @"ゲ" from : @"ｹﾞ" ];
	message = [ message convertTo : @"ゴ" from : @"ｺﾞ" ];
	message = [ message convertTo : @"ザ" from : @"ｻﾞ" ];
	message = [ message convertTo : @"ジ" from : @"ｼﾞ" ];
	message = [ message convertTo : @"ズ" from : @"ｽﾞ" ];
	message = [ message convertTo : @"ゼ" from : @"ｾﾞ" ];
	message = [ message convertTo : @"ゾ" from : @"ｿﾞ" ];
	message = [ message convertTo : @"ダ" from : @"ﾀﾞ" ];
	message = [ message convertTo : @"ヂ" from : @"ﾁﾞ" ];
	message = [ message convertTo : @"ヅ" from : @"ﾂﾞ" ];
	message = [ message convertTo : @"デ" from : @"ﾃﾞ" ];
	message = [ message convertTo : @"ド" from : @"ﾄﾞ" ];
	message = [ message convertTo : @"バ" from : @"ﾊﾞ" ];
	message = [ message convertTo : @"ビ" from : @"ﾋﾞ" ];
	message = [ message convertTo : @"ブ" from : @"ﾌﾞ" ];
	message = [ message convertTo : @"ベ" from : @"ﾍﾞ" ];
	message = [ message convertTo : @"ボ" from : @"ﾎﾞ" ];
	message = [ message convertTo : @"パ" from : @"ﾊﾟ" ];
	message = [ message convertTo : @"ピ" from : @"ﾋﾟ" ];
	message = [ message convertTo : @"プ" from : @"ﾌﾟ" ];
	message = [ message convertTo : @"ペ" from : @"ﾍﾟ" ];
	message = [ message convertTo : @"ポ" from : @"ﾎﾟ" ];
	
	message = [ message convertTo : @"バ" from : @"ｳﾞｧ" ];
	message = [ message convertTo : @"ビ" from : @"ｳﾞｨ" ];
	message = [ message convertTo : @"ベ" from : @"ｳﾞｪ" ];
	message = [ message convertTo : @"ボ" from : @"ｳﾞｫ" ];
	message = [ message convertTo : @"ブ" from : @"ｳﾞ" ];
	
	// 50音
	message = [ message convertTo : @"ア" from : @"ｱ" ];
	message = [ message convertTo : @"イ" from : @"ｲ" ];
	message = [ message convertTo : @"ウ" from : @"ｳ" ];
	message = [ message convertTo : @"エ" from : @"ｴ" ];
	message = [ message convertTo : @"オ" from : @"ｵ" ];
	message = [ message convertTo : @"カ" from : @"ｶ" ];
	message = [ message convertTo : @"キ" from : @"ｷ" ];
	message = [ message convertTo : @"ク" from : @"ｸ" ];
	message = [ message convertTo : @"ケ" from : @"ｹ" ];
	message = [ message convertTo : @"コ" from : @"ｺ" ];
	message = [ message convertTo : @"サ" from : @"ｻ" ];
	message = [ message convertTo : @"シ" from : @"ｼ" ];
	message = [ message convertTo : @"ス" from : @"ｽ" ];
	message = [ message convertTo : @"セ" from : @"ｾ" ];
	message = [ message convertTo : @"ソ" from : @"ｿ" ];
	message = [ message convertTo : @"タ" from : @"ﾀ" ];
	message = [ message convertTo : @"チ" from : @"ﾁ" ];
	message = [ message convertTo : @"ツ" from : @"ﾂ" ];
	message = [ message convertTo : @"テ" from : @"ﾃ" ];
	message = [ message convertTo : @"ト" from : @"ﾄ" ];
	message = [ message convertTo : @"ナ" from : @"ﾅ" ];
	message = [ message convertTo : @"ニ" from : @"ﾆ" ];
	message = [ message convertTo : @"ヌ" from : @"ﾇ" ];
	message = [ message convertTo : @"ネ" from : @"ﾈ" ];
	message = [ message convertTo : @"ノ" from : @"ﾉ" ];
	message = [ message convertTo : @"ハ" from : @"ﾊ" ];
	message = [ message convertTo : @"ヒ" from : @"ﾋ" ];
	message = [ message convertTo : @"フ" from : @"ﾌ" ];
	message = [ message convertTo : @"ヘ" from : @"ﾍ" ];
	message = [ message convertTo : @"ホ" from : @"ﾎ" ];
	message = [ message convertTo : @"マ" from : @"ﾏ" ];
	message = [ message convertTo : @"ミ" from : @"ﾐ" ];
	message = [ message convertTo : @"ム" from : @"ﾑ" ];
	message = [ message convertTo : @"メ" from : @"ﾒ" ];
	message = [ message convertTo : @"モ" from : @"ﾓ" ];
	message = [ message convertTo : @"ヤ" from : @"ﾔ" ];
	message = [ message convertTo : @"ユ" from : @"ﾕ" ];
	message = [ message convertTo : @"ヨ" from : @"ﾖ" ];
	message = [ message convertTo : @"ラ" from : @"ﾗ" ];
	message = [ message convertTo : @"リ" from : @"ﾘ" ];
	message = [ message convertTo : @"ル" from : @"ﾙ" ];
	message = [ message convertTo : @"レ" from : @"ﾚ" ];
	message = [ message convertTo : @"ロ" from : @"ﾛ" ];
	message = [ message convertTo : @"ワ" from : @"ﾜ" ];
	message = [ message convertTo : @"ヲ" from : @"ｦ" ];
	message = [ message convertTo : @"ン" from : @"ﾝ" ];
	
	// 小文字
	message = [ message convertTo : @"ァ" from : @"ｧ" ];
	message = [ message convertTo : @"ィ" from : @"ｨ" ];
	message = [ message convertTo : @"ゥ" from : @"ｩ" ];
	message = [ message convertTo : @"ェ" from : @"ｪ" ];
	message = [ message convertTo : @"ォ" from : @"ｫ" ];
	message = [ message convertTo : @"ャ" from : @"ｬ" ];
	message = [ message convertTo : @"ュ" from : @"ｭ" ];
	message = [ message convertTo : @"ョ" from : @"ｮ" ];
	message = [ message convertTo : @"ッ" from : @"ｯ" ];
	
	// その他
	message = [ message convertTo : @"ー" from : @"ｰ" ];
	message = [ message convertTo : @"、" from : @"､" ];
	message = [ message convertTo : @"。" from : @"｡" ];
	
	return message;
}


@end
